package com.test.demo.mydubbo.framework.protocol.dubbo.coder;

import com.alibaba.fastjson.JSON;
import com.test.demo.mydubbo.framework.protocol.DataFormater;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.ByteToMessageDecoder;

import java.util.List;

public class DataFormaterDecoder extends ByteToMessageDecoder{

    protected void decode(ChannelHandlerContext channelHandlerContext, ByteBuf byteBuf, List<Object> list) throws Exception {
        byte[] array = Unpooled.copiedBuffer(byteBuf).array();
        DataFormater dataFormater = JSON.parseObject(new String(array), DataFormater.class);
        list.add(dataFormater);
        //指针移动到最开始
        byteBuf.skipBytes(byteBuf.readableBytes());
    }
}
